import { createSlice, PayloadAction } from '@reduxjs/toolkit';
import type { RootState } from '../store';

interface LoginState {
    token: string;
}

const initialState: LoginState = {
    token: '',
};

export const loginSlice = createSlice({
    name: 'login',
    initialState,
    reducers: {
        addtoken: (state, action: PayloadAction<string>) => {
            state.token = action.payload;
        },
    },
});
// 每个 case reducer 函数会生成对应的 Action creators
export const { addtoken } = loginSlice.actions;
export const selectLogin = (state: RootState) => state.login.token;
export default loginSlice.reducer;
